home *** CD-ROM | disk | FTP | other *** search
/ Mastering Public Speaking / Mastering Public Speaking.iso / pc / Click Here.exe / Click Here.dxr / Internal_57_Color Cycling.ls < prev    next >
Encoding:
Text File  |  2003-05-13  |  5.0 KB  |  122 lines

  1. property pSprite, pColorStart, pColorEnd, pCycleStart, pCycleEnd, pColorRDiff, pColorGDiff, pColorBDiff, pCycleMillis, pCyclesComplete, pColorMode, pCyclePeriod, pColorCycles, pColor1R, pColor1G, pColor1B, pColor2R, pColor2G, pColor2B
  2.  
  3. on getBehaviorDescription me
  4.   return "COLOR CYCLING" & RETURN & RETURN & "Use this behavior to create a color animation effect. " & "The sprite will change over a period of time, from one color to another. " & "You can use either RGB colors or palette indices. " & "The speed of the color cycle can be set, as can the number of times that the color cycles." & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Color mode (RGB or palette index)" & RETURN & "* Cycle period in seconds" & RETURN & "* Number of cycles" & RETURN & "* Start color" & RETURN & "* End color" & RETURN & RETURN & "To make the color change once (from the start color to the end color) set the number of cycles to 0. " & "To cycle forever, set it to -1."
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Cycles a sprite's color through a range of either RGB colors or palette indices. " & "Cycling can be continuous or for a specific number of cycles. " & "The cycle rate can also be set."
  9. end
  10.  
  11. on beginSprite me
  12.   pColorMode = resolve(pColorMode)
  13.   mInitialize(me)
  14. end
  15.  
  16. on resolve prop
  17.   choiceslist = ["Palette", "RGB"]
  18.   lookup = [#palette, #rgb]
  19.   return lookup[findPos(choiceslist, prop)]
  20. end
  21.  
  22. on prepareFrame me
  23.   mUpdate(me)
  24. end
  25.  
  26. on mInitialize me
  27.   pSprite = sprite(me.spriteNum)
  28.   pCyclesComplete = 0.5
  29.   pCycleMillis = integer(pCyclePeriod * 1000)
  30.   mInitColors(me)
  31. end
  32.  
  33. on mUpdate me
  34.   vTime = the milliSeconds
  35.   vElapsed = vTime - pCycleStart
  36.   if vTime >= pCycleEnd then
  37.     pSprite.color = pColorEnd
  38.     pCyclesComplete = pCyclesComplete + 0.5
  39.     case pColorCycles of
  40.       (-1):
  41.         mInitColors(me)
  42.       0:
  43.         nothing()
  44.       otherwise:
  45.         if pCyclesComplete <= pColorCycles then
  46.           mInitColors(me)
  47.         end if
  48.     end case
  49.   else
  50.     if pColorMode = #rgb then
  51.       vRed = pColorStart.red + (pColorRDiff * vElapsed / pCycleMillis)
  52.       vGreen = pColorStart.green + (pColorGDiff * vElapsed / pCycleMillis)
  53.       vBlue = pColorStart.blue + (pColorBDiff * vElapsed / pCycleMillis)
  54.       pSprite.color = rgb(vRed, vGreen, vBlue)
  55.     else
  56.       vRed = pColorStart.paletteIndex + (pColorRDiff * vElapsed / pCycleMillis)
  57.       pSprite.color = paletteIndex(vRed)
  58.     end if
  59.   end if
  60. end
  61.  
  62. on mInitColors me
  63.   if integer(pCyclesComplete * 2) <> (integer(pCyclesComplete) * 2) then
  64.     vStartColorList = [pColor1R, pColor1G, pColor1B]
  65.     vEndColorList = [pColor2R, pColor2G, pColor2B]
  66.   else
  67.     vStartColorList = [pColor2R, pColor2G, pColor2B]
  68.     vEndColorList = [pColor1R, pColor1G, pColor1B]
  69.   end if
  70.   if pColorMode = #rgb then
  71.     pColorStart = rgb(vStartColorList[1], vStartColorList[2], vStartColorList[3])
  72.     pColorEnd = rgb(vEndColorList[1], vEndColorList[2], vEndColorList[3])
  73.   else
  74.     pColorStart = paletteIndex(vStartColorList[1])
  75.     pColorEnd = paletteIndex(vEndColorList[1])
  76.   end if
  77.   pColorRDiff = vEndColorList[1] - vStartColorList[1]
  78.   pColorGDiff = vEndColorList[2] - vStartColorList[2]
  79.   pColorBDiff = vEndColorList[3] - vStartColorList[3]
  80.   pCycleStart = the milliSeconds
  81.   pCycleEnd = pCycleStart + pCycleMillis
  82.   pSprite.color = pColorStart
  83. end
  84.  
  85. on isOKToAttach me, aSpriteType, aSpriteNum
  86.   case aSpriteType of
  87.     #graphic:
  88.       return getPos([#animGif, #bitmap, #flash, #shape, #text], sprite(aSpriteNum).member.type) <> 0
  89.     #script:
  90.       return 0
  91.   end case
  92. end
  93.  
  94. on getPropertyDescriptionList me
  95.   if not (the currentSpriteNum) then
  96.     exit
  97.   end if
  98.   vRect = (the stage).rect
  99.   vColor = sprite(the currentSpriteNum).color
  100.   vColorType = vColor.colorType
  101.   if vColorType = #rgb then
  102.     vRed = vColor.red
  103.     vGreen = vColor.green
  104.     vBlue = vColor.blue
  105.   else
  106.     vRed = vColor.paletteIndex
  107.     vGreen = 0
  108.     vBlue = 0
  109.   end if
  110.   vPDList = [:]
  111.   setaProp(vPDList, #pColorMode, [#comment: "Color mode", #format: #string, #default: "Palette", #range: ["Palette", "RGB"]])
  112.   setaProp(vPDList, #pCyclePeriod, [#comment: "Cycle period (seconds)", #format: #float, #default: 3, #range: [#min: 1, #max: 25]])
  113.   setaProp(vPDList, #pColorCycles, [#comment: "Color cycles", #format: #integer, #default: 0, #range: [#min: -1, #max: 100]])
  114.   setaProp(vPDList, #pColor1R, [#comment: "Start color: palette index or Red component", #format: #integer, #default: vRed, #range: [#min: 0, #max: 255]])
  115.   setaProp(vPDList, #pColor1G, [#comment: "Green component", #format: #integer, #default: vGreen, #range: [#min: 0, #max: 255]])
  116.   setaProp(vPDList, #pColor1B, [#comment: "Blue Component", #format: #integer, #default: vBlue, #range: [#min: 0, #max: 255]])
  117.   setaProp(vPDList, #pColor2R, [#comment: "Final color: palette index or Red component", #format: #integer, #default: 255 - vRed, #range: [#min: 0, #max: 255]])
  118.   setaProp(vPDList, #pColor2G, [#comment: "Green component", #format: #integer, #default: 255 - vGreen, #range: [#min: 0, #max: 255]])
  119.   setaProp(vPDList, #pColor2B, [#comment: "Blue Component", #format: #integer, #default: 255 - vBlue, #range: [#min: 0, #max: 255]])
  120.   return vPDList
  121. end
  122.